﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MLSMooc.Session
{

    public static class SessionBaseOpt
    {
        public static bool IsSessionExist(string index)
        {
            return HttpContextProvider.Current.Session[index] != null;
        }

        //public static T GetSessionState<T>(string index)
        //{
        //    return (T)HttpContext.Current.Session[index];
        //}

        public static T GetSessionState<T>(string index, object defaultValue)
        {
            return HttpContextProvider.Current.Session[index] == null ? (T)defaultValue : (T)HttpContextProvider.Current.Session[index];
        }

        public static void SetSessionState(string index, object value)
        {
            HttpContextProvider.Current.Session[index] = value;
        }

        public static void ClearSession()
        {
            HttpContextProvider.Current.Session.Clear();
        }

        public static void ClearSession(string index)
        {
            HttpContextProvider.Current.Session.Remove(index);
        }
    }
}